#ifndef LIST_H_
#define LIST_H_
//#include "Object.h"
#include <stdio.h>
template <class T>
class List
{
	public:
	
	List<T> * next;
	List<T> * prev;
	T * payload;
	List( T * payload, List * head);
	~List();
	List * Remove();
	List<T> * RemoveList();
	void Test();
		
};

template<class T>
List<T>::List( T * payload, List<T> * head)
{
	this->prev = NULL;
	this->payload = payload;
	this->next = head;
	
	if(head)
		head->prev = this;
}

template<class T>
List<T>::~List()
{
	Remove();
}

template<class T>
List<T> * List<T>::Remove()
{
	//printf("removing list member\n");
	List * next = this->next;
	if( prev)
		prev->next = next;
	//printf("removing list member2\n");
	if( next)
		next->prev = prev;
	//printf("removing list member3\n");
	if(payload)
	{
		delete payload;
		//printf("done deleting payload\n");
	}

	payload = NULL;
	//printf("leaving remove list member\n");
	return next;
}

template<class T>
List<T> * List<T>::RemoveList()
{
	//printf("removing list member\n");
	List * next = this->next;
	if( prev)
		prev->next = next;
	//printf("removing list member2\n");
	if( next)
		next->prev = prev;
	//printf("removing list member3\n");

	payload = NULL;
	//printf("leaving remove list member\n");
	return next;
}

#endif /*LIST_H_*/
